package com.xiaoyu.base.entity;

import androidx.room.Entity;
import androidx.room.PrimaryKey;
import androidx.room.TypeConverters;

import com.xiaoyu.base.converter.StringListConverter;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

import in.srain.cube.request.JsonData;

@Entity(tableName = "sticker_package")
public class StickerPackage {

    @PrimaryKey
    private long packageId;
    private long ord;
    private String authorUid;
    private String title;
    private String desc;
    private String fromDesc;
    private String status;
    private String cover;
    @TypeConverters({StringListConverter.class})
    private List<String> urls;

    public StickerPackage() {
        this.packageId = 0;
        this.ord = 0;
        this.authorUid = "";
        this.title = "";
        this.desc = "";
        this.fromDesc = "";
        this.status = "";
        this.cover = "";
        this.urls = new ArrayList<>();
    }

    public StickerPackage(JsonData jsonData) {
        this.ord = jsonData.optLong("ord");
        this.packageId = jsonData.optLong("package_id");
        this.authorUid = jsonData.optJson("user").optString("id");
        this.title = jsonData.optString("title");
        this.desc = jsonData.optString("desc");
        this.fromDesc = jsonData.optString("from_desc");
        this.status = jsonData.optString("status");
        this.cover = jsonData.optString("cover");
        this.urls = jsonData.optJson("urls").asList();
    }

    public long getPackageId() {
        return packageId;
    }

    public void setPackageId(long packageId) {
        this.packageId = packageId;
    }

    public long getOrd() {
        return ord;
    }

    public void setOrd(long ord) {
        this.ord = ord;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }

    public String getFromDesc() {
        return fromDesc;
    }

    public void setFromDesc(String fromDesc) {
        this.fromDesc = fromDesc;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public String getCover() {
        return cover;
    }

    public void setCover(String cover) {
        this.cover = cover;
    }

    public List<String> getUrls() {
        return urls;
    }

    public void setUrls(List<String> urls) {
        this.urls = urls;
    }

    public String getAuthorUid() {
        return authorUid;
    }

    public void setAuthorUid(String authorUid) {
        this.authorUid = authorUid;
    }

    @Override
    public String toString() {
        return "StickerPackage{" +
                "packageId=" + packageId +
                ", ord=" + ord +
                ", authorUid='" + authorUid + '\'' +
                ", title='" + title + '\'' +
                ", desc='" + desc + '\'' +
                ", fromDesc='" + fromDesc + '\'' +
                ", status='" + status + '\'' +
                ", cover='" + cover + '\'' +
                ", urls=" + urls +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o)
            return true;
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        StickerPackage stickerPackage = (StickerPackage) o;
        return packageId == stickerPackage.packageId;
    }

    @Override
    public int hashCode() {
        return Objects.hash(packageId);
    }
}
